package offer

import (
	sqlc "bp/db/sqlc"
	sharedConv "bp/internal/rpcserver/shared/conv"
	"bp/internal/service/com/offer"
	offerGrpc "bp/rpc/gen/mwebapi/offer"
)

type OfferPtrEntityToPbFunc func(*offer.Offer) *offerGrpc.OfferEntity
type OfferPtrArrayEntityToPbFunc func([]*offer.Offer) []*offerGrpc.OfferEntity

// ConvOfferPtrEntityToPb get func of *offer.Offer => *offerGrpc.OfferEntity
func (s *OfferMWebApiImp) ConvOfferPtrEntityToPb() OfferPtrEntityToPbFunc {
	return func(ptr *offer.Offer) *offerGrpc.OfferEntity {
		if ptr == nil {
			return nil
		}
		return &offerGrpc.OfferEntity{
			Id:                      ptr.ID,
			Name:                    ptr.Name,
			Desc:                    ptr.Desc,
			Tags:                    ptr.Tags,
			Nature:                  ptr.Nature,
			OfferCategory:           ptr.OfferCategory,
			OfferType:               ptr.OfferType,
			NeedVerifyQualification: ptr.NeedVerifyQualification,
			QualifyTypes:            ptr.QualifyTypes,
			Price:                   ptr.Price,
			Quota:                   ptr.Quota,
			OffMaximum:              ptr.OffMaximum,
			GradientRules:           sharedConv.ConvOffGradientRuleArrayEntityToPb(ptr.GradientRules),
			UsePeriodType:           ptr.UsePeriodType,
			Days:                    ptr.Days,
			AvailableAfterGotDays:   ptr.AvailableAfterGotDays,
			Begined:                 sqlc.GoTimeToPBTimestamp(ptr.Begined),
			Ended:                   sqlc.GoTimeToPBTimestamp(ptr.Ended),
		}
	}
}

// ConvOfferPtrArrayEntityToPb get func of []*offer.Offer => []*offerGrpc.OfferEntity
func (s *OfferMWebApiImp) ConvOfferPtrArrayEntityToPb() OfferPtrArrayEntityToPbFunc {
	return func(ptrs []*offer.Offer) (vPtrs []*offerGrpc.OfferEntity) {
		for _, ptr := range ptrs {
			vPtrs = append(vPtrs, s.ConvOfferPtrEntityToPb()(ptr))
		}
		return
	}
}
